'use client';

import { Input } from '@/components/ui/Input';
import { Textarea } from '@/components/ui/Textarea';
import SubmitButton from './SubmitButton';
import { createApp } from './actions';
import { redirect, useRouter } from 'next/navigation';

/**
 * App概念提出的地方，创建一个图床应用
 */
export default function CreateApp() {
  const router = useRouter();
  return (
    <div className="h-full flex justify-center items-center">
      <form
        className="w-full max-w-md flex flex-col gap-4"
        action={async (formData: FormData) => {
          const appId = await createApp(formData);
          redirect(`/dashboard/apps/${appId}`);
        }}
      >
        <h1 className="text-center text-2xl font-bold">Create App</h1>
        <Input
          name="name"
          placeholder="App Name"
          minLength={3}
          required
        ></Input>
        <Textarea name="description" placeholder="Description"></Textarea>
        <SubmitButton />
      </form>
    </div>
  );
}
